#ifndef						_ATTRIBUTE_H_
#define						_ATTRIBUTE_H_

#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <vector>
#include <string.h>

template <typename T>
T StringTo(const std::string &s)
{
	T x;

	//check for boolean keywords
	if(s.find("true") != std::string::npos) 
		x = 1;
	else if(s.find("false") != std::string::npos) 
		x = 0;
	else
	{
		std::stringstream ss;

		//Check for Hex input
		if(s.size() > 1)
		{
			if(s[0] == '0' && tolower(s[1]) == 'x')
			{
				//If first two characters are Hex characters set
				//the stringstream to base 16
				ss << std::setbase(16); 
			}
		}

		//Read the string into the stringstream
		ss.str(s);

		//Write to the destination type
		if(!(ss >> x)) 
			throw std::runtime_error("Invalid value for destination type");
	}
	return x;
}

class CAttribute
{
public:
	CAttribute(std::string attr);
	CAttribute(std::string attr, std::string deliminator);
	~CAttribute();

	std::vector<std::string>	List();
	int							ReadAsInt(const std::string name);
	float						ReadAsFloat(const std::string name);
	std::vector<float>			ReadAsVectorFloat(const std::string name, unsigned int nSize);
	std::vector<int>			ReadAsVectorInt(const std::string name, unsigned int nSize);
	std::string					ReadAsString(const std::string name);
	std::vector<std::string>	ReadAsVectorStringXML(const std::string name);
	void						Deserialize(const std::string attr);

	static std::vector<std::string>	Tokenize(const std::string& str, 
		const std::string& delimiters);

private:
	std::vector<std::string>	m_attrList;
	std::string					m_deliminator;

	int							m_ReadAsInt(const std::string name);
	float						m_ReadAsFloat(const std::string name);
	std::vector<float>			m_ReadAsVectorFloat(const std::string name, unsigned int nSize);
	std::vector<int>			m_ReadAsVectorInt(const std::string name, unsigned int nSize);
	std::string					m_ReadAsString(const std::string name);
	void						t_Tokenize(const std::string& str, 
										   const std::string& delimiters);

protected:

};

#endif						//_ATTRIBUTE_H_
